package cn.rbac.util;

import org.hibernate.SessionFactory;
import org.hibernate.boot.registry.StandardServiceRegistry;
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
import org.hibernate.cfg.Configuration;

public class HibernateUtil {
	
		private static SessionFactory sessionFactory;
		
		private HibernateUtil(){
			
		}
		
		synchronized public static SessionFactory getSessionFactory(){
			if(sessionFactory==null){
				Configuration cfg=new Configuration().configure();
				StandardServiceRegistryBuilder builder=new StandardServiceRegistryBuilder().applySettings(cfg.getProperties());
				StandardServiceRegistry registry=builder.build();
				sessionFactory=cfg.buildSessionFactory(registry);
			}
			return sessionFactory;
		}
		
}
